<?php
function autoLoader($className){
    $directories = array(
        '', 'ui/', 'classes/', 'helper/',
        'classes/model/',
        'classes/dao/',
        'classes/dao/impl',
        'classes/service',
        'classes/service/impl'
    );

    $fileNameFormats = array(
      '%s.php',
      '%s.class.php',
      'class.%s.php',
      '%s.inc.php'
    );

    $path = str_ireplace('_', '/', $className);
    if(@include_once $path.'.php'){
        return;
    }

    foreach($directories as $directory){
        foreach($fileNameFormats as $fileNameFormat){
            $path = $directory.sprintf($fileNameFormat, $className);
            if(file_exists($path)){
                include_once $path;
                return;
            }
        }
    }
}

spl_autoload_register('autoLoader');

set_include_path(
    dirname(__FILE__) . '/lib/orm'
    . PATH_SEPARATOR . dirname(__FILE__) . '/ui'
    . PATH_SEPARATOR . dirname(__FILE__) . 'helper/'
    . PATH_SEPARATOR . dirname(__FILE__) . '/classes'
    . PATH_SEPARATOR . dirname(__FILE__) . '/classes/model'
    . PATH_SEPARATOR . dirname(__FILE__) . '/classes/dao'
    . PATH_SEPARATOR . dirname(__FILE__) . '/classes/dao/impl'
    . PATH_SEPARATOR . dirname(__FILE__) . '/classes/service'
    . PATH_SEPARATOR . dirname(__FILE__) . '/classes/service/impl'
    . PATH_SEPARATOR . get_include_path()
);

?>